package com.hellomeng.delegate;

//都写道一个文件中了，方便看
//协议
interface ZuFangHeYue{
    public void qianhetong();
}

//代理类（中介)，必须指定好
class ZhongJieProxy implements ZuFangHeYue{
    private ZuKe zuke;//代理谁

    //构造方法-通过构造方法，知道哪个租客召唤自己
    public ZhongJieProxy(ZuKe zuke){
        this.zuke = zuke;
    }

    //代理类技能1：找房子
    public void zhaoFangZi(){
        System.out.println("替租客找房源");
    }
    //代理类技能2：看房子
    public void kanFangZi(){
        System.out.println("替租客实地看房");
    }
    @Override
    public void qianhetong() {
        zhaoFangZi();//替租客做
        kanFangZi(); //替租客做
        zuke.qianhetong();//最终让租客自己签合同
    }
}

//被代理类（租客），也要指定好
class ZuKe implements ZuFangHeYue{

    @Override
    public void qianhetong() {
        System.out.println("租客签合同");
    }
}


public class TestStaticDelegate {
    public static void main(String[] args) {
        //1.租客出现
        ZuKe zuke = new ZuKe();
        //2.召唤中介
        ZhongJieProxy proxy = new ZhongJieProxy(zuke);
        //3.中介代理租客租房子
        proxy.qianhetong();//1.找房源，2.看房子，3.接租客来签合同
    }
}


